import 'dart:typed_data';

import 'package:bluetooth_protocols_parser_plugin/src/lorin/lorin_helper.dart';
import 'package:bluetooth_protocols_parser_plugin/src/tools/costant.dart';
import 'package:bluetooth_protocols_plugin/library.dart';

import '../../enum/target_device_type.dart';

class P6IntegratedProductInfo extends LorinIntegratedProductionInfo {
  List<Map<String, dynamic>> firmwareInfo = [];

  P6IntegratedProductInfo.fromBytes(Uint8List bytes) : super.fromBytes(bytes) {
    if (bytes.length < minLength) {
      throw ArgumentError(
          '$runtimeType Bytes length is less than minimum required length.');
    }
    int offset = minLength;
    int firmwaresLength = LORIN_ONCE_FIRMWARE_VERSION_LENGTH *
        targetDevices.length; // 每个设备类型占用9个字节
    firmwareInfo = LorinHelper.getVersions(
        bytes.sublist(offset, offset + firmwaresLength));
  }

  // 将对象转换为Map
  @override
  Map<String, dynamic> toMap() {
    var map = super.toMap(); // 先获取父类的 Map
    map['firmware_info'] = firmwareInfo;
    map['version'] = '$runtimeType';
    return map;
  }

  @override
  List<int> get targetDevices => [
        TargetDeviceType.eucHmic.rawValue,
        TargetDeviceType.eucDriver.rawValue,
        TargetDeviceType.eucBle.rawValue,
        TargetDeviceType.eucBMS1.rawValue,
        TargetDeviceType.eucBMS2.rawValue,
        TargetDeviceType.eucDc.rawValue,
        TargetDeviceType.eucTBox.rawValue,
      ];
}
